home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / sys5 / iscwmpst.z / iscwmpst / tcp / src / ip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-10  |  7.4 KB  |  210 lines

  1. /* @(#) $Header: ip.h,v 1.7 91/05/09 07:38:24 deyke Exp $ */
  2.  
  3. #ifndef _IP_H
  4. #define _IP_H
  5.  
  6. #ifndef _GLOBAL_H
  7. #include "global.h"
  8. #endif
  9.  
  10. #ifndef _MBUF_H
  11. #include "mbuf.h"
  12. #endif
  13.  
  14. #ifndef _IFACE_H
  15. #include "iface.h"
  16. #endif
  17.  
  18. #ifndef _INTERNET_H
  19. #include "internet.h"
  20. #endif
  21.  
  22. #ifndef _TIMER_H
  23. #include "timer.h"
  24. #endif
  25.  
  26. #define TLB     30      /* Default reassembly timeout, sec */
  27. #define IPVERSION       4
  28. #define IP_MAXOPT       40      /* Largest option field, bytes */
  29.  
  30. extern int32 Ip_addr;   /* Our IP address for ICMP and source routing */
  31. extern char Hashtab[];  /* Modulus lookup table */
  32.  
  33. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  34. extern struct mib_entry Ip_mib[];
  35. #define ipForwarding            Ip_mib[1].value.integer
  36. #define ipDefaultTTL            Ip_mib[2].value.integer
  37. #define ipInReceives            Ip_mib[3].value.integer
  38. #define ipInHdrErrors           Ip_mib[4].value.integer
  39. #define ipInAddrErrors          Ip_mib[5].value.integer
  40. #define ipForwDatagrams         Ip_mib[6].value.integer
  41. #define ipInUnknownProtos       Ip_mib[7].value.integer
  42. #define ipInDiscards            Ip_mib[8].value.integer
  43. #define ipInDelivers            Ip_mib[9].value.integer
  44. #define ipOutRequests           Ip_mib[10].value.integer
  45. #define ipOutDiscards           Ip_mib[11].value.integer
  46. #define ipOutNoRoutes           Ip_mib[12].value.integer
  47. #define ipReasmTimeout          Ip_mib[13].value.integer
  48. #define ipReasmReqds            Ip_mib[14].value.integer
  49. #define ipReasmOKs              Ip_mib[15].value.integer
  50. #define ipReasmFails            Ip_mib[16].value.integer
  51. #define ipFragOKs               Ip_mib[17].value.integer
  52. #define ipFragFails             Ip_mib[18].value.integer
  53. #define ipFragCreates           Ip_mib[19].value.integer
  54.  
  55. #define NUMIPMIB        19
  56.  
  57. /* IP header, INTERNAL representation */
  58. struct ip {
  59.     char version;           /* IP version number */
  60.     char tos;               /* Type of service */
  61.     int16 length;           /* Total length */
  62.     int16 id;               /* Identification */
  63.     int16 offset;           /* Fragment offset in bytes */
  64.     struct {
  65.         char congest;   /* Congestion experienced bit (exp) */
  66.         char df;        /* Don't fragment flag */
  67.         char mf;        /* More Fragments flag */
  68.     } flags;
  69.  
  70.     char ttl;               /* Time to live */
  71.     char protocol;          /* Protocol */
  72.     int16 checksum;         /* Header checksum */
  73.     int32 source;           /* Source address */
  74.     int32 dest;             /* Destination address */
  75.     char options[IP_MAXOPT];/* Options field */
  76.     int optlen;             /* Length of options field, bytes */
  77. };
  78. #define NULLIP  (struct ip *)0
  79. #define IPLEN   20      /* Length of standard IP header */
  80.  
  81. /* Fields in option type byte */
  82. #define OPT_COPIED      0x80    /* Copied-on-fragmentation flag */
  83. #define OPT_CLASS       0x60    /* Option class */
  84. #define OPT_NUMBER      0x1f    /* Option number */
  85.  
  86. /* IP option numbers */
  87. #define IP_EOL          0       /* End of options list */
  88. #define IP_NOOP         1       /* No Operation */
  89. #define IP_SECURITY     2       /* Security parameters */
  90. #define IP_LSROUTE      3       /* Loose Source Routing */
  91. #define IP_TIMESTAMP    4       /* Internet Timestamp */
  92. #define IP_RROUTE       7       /* Record Route */
  93. #define IP_STREAMID     8       /* Stream ID */
  94. #define IP_SSROUTE      9       /* Strict Source Routing */
  95.  
  96. /* Timestamp option flags */
  97. #define TS_ONLY         0       /* Time stamps only */
  98. #define TS_ADDRESS      1       /* Addresses + Time stamps */
  99. #define TS_PRESPEC      3       /* Prespecified addresses only */
  100.  
  101. /* IP routing table entry */
  102. struct route {
  103.     struct route *prev;     /* Linked list pointers */
  104.     struct route *next;
  105.     int32 target;           /* Target IP address */
  106.     unsigned int bits;      /* Number of significant bits in target */
  107.     int32 gateway;          /* IP address of local gateway for this target */
  108.     int32 metric;           /* Hop count or whatever */
  109.     struct iface *iface;    /* Device interface structure */
  110.     int flags;
  111. #define RTPRIVATE       0x1     /* Should the world be told of this route ? */
  112. #define RTTRIG  0x2             /* Trigger is pending for this route */
  113.     struct timer timer;     /* Time until aging of this entry */
  114.     int32 uses;             /* Usage count */
  115. };
  116. #define NULLROUTE       (struct route *)0
  117. extern struct route *Routes[32][HASHMOD];       /* Routing table */
  118. extern struct route R_default;                  /* Default route entry */
  119.  
  120. /* Cache for the last-used routing entry, speeds up the common case where
  121.  * we handle a burst of packets to the same destination
  122.  */
  123. struct rt_cache {
  124.     int32 target;
  125.     struct route *route;
  126. };
  127.  
  128. /* Reassembly descriptor */
  129. struct reasm {
  130.     struct reasm *next;     /* Linked list pointer */
  131.     struct timer timer;     /* Reassembly timeout timer */
  132.     struct frag *fraglist;  /* Head of data fragment chain */
  133.     int16 length;           /* Entire datagram length, if known */
  134.     int32 source;           /* src/dest/id/protocol uniquely describe a datagram */
  135.     int32 dest;
  136.     int16 id;
  137.     char protocol;
  138. };
  139. #define NULLREASM       (struct reasm *)0
  140.  
  141. /* Fragment descriptor in a reassembly list */
  142. struct frag {
  143.     struct frag *prev;      /* Previous fragment on list */
  144.     struct frag *next;      /* Next fragment */
  145.     struct mbuf *buf;       /* Actual fragment data */
  146.     int16 offset;           /* Starting offset of fragment */
  147.     int16 last;             /* Ending offset of fragment */
  148. };
  149. #define NULLFRAG        (struct frag *)0
  150.  
  151. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  152.  
  153. /* Structure for handling raw IP user sockets */
  154. struct raw_ip {
  155.     struct raw_ip *next;    /* Linked list pointer */
  156.  
  157.     struct mbuf *rcvq;      /* receive queue */
  158.     void (*r_upcall) __ARGS((struct raw_ip *));
  159.     int protocol;           /* Protocol */
  160.     int user;               /* User linkage */
  161. };
  162. #define NULLRIP ((struct raw_ip *)0)
  163.  
  164. /* Transport protocol link table */
  165. struct iplink {
  166.     char proto;
  167.     void (*funct) __ARGS((struct iface *,struct ip *,struct mbuf *,int));
  168. };
  169. extern struct iplink Iplink[];
  170.  
  171. /* In ip.c: */
  172. void ip_garbage __ARGS((int drastic));
  173. void ip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  174.     int rxbroadcast));
  175. void ipip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  176.     int rxbroadcast));
  177. int ip_send __ARGS((int32 source,int32 dest,int protocol,int tos,int ttl,
  178.     struct mbuf *bp,int length,int id,int df));
  179. struct raw_ip *raw_ip __ARGS((int protocol,void (*r_upcall) __ARGS((struct raw_ip *)) ));
  180. void del_ip __ARGS((struct raw_ip *rrp));
  181.  
  182. /* In iproute.c: */
  183. void ipinit __ARGS((void));
  184. int16 ip_mtu __ARGS((int32 addr));
  185. int ip_encap __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,
  186.     int prec,int del,int tput,int rel));
  187. int ip_route __ARGS((struct iface *i_iface,struct mbuf *bp,int rxbroadcast));
  188. int32 locaddr __ARGS((int32 addr));
  189. void rt_merge __ARGS((int trace));
  190. struct route *rt_add __ARGS((int32 target,unsigned int bits,int32 gateway,
  191.     struct iface *iface,int32 metric,int32 ttl,int private));
  192. int rt_drop __ARGS((int32 target,unsigned int bits));
  193. struct route *rt_lookup __ARGS((int32 target));
  194. struct route *rt_blookup __ARGS((int32 target,unsigned int bits));
  195.  
  196. /* In iphdr.c: */
  197. int16 cksum __ARGS((struct pseudo_header *ph,struct mbuf *m,int len));
  198. int16 eac __ARGS((int32 sum));
  199. struct mbuf *htonip __ARGS((struct ip *ip,struct mbuf *data,int cflag));
  200. int ntohip __ARGS((struct ip *ip,struct mbuf **bpp));
  201.  
  202. /* In either lcsum.c or pcgen.asm: */
  203. int16 lcsum __ARGS((int16 *wp,int len));
  204.  
  205. /* In ipfile.c: */
  206. void route_savefile __ARGS((void));
  207. void route_loadfile __ARGS((void));
  208.  
  209. #endif /* _IP_H */
  210.